#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

#AC_PREREQ([2.63])
AC_INIT([broomie], [0.2.4], [bramtrain@gmail.com])
AC_CONFIG_SRCDIR([config.h.in])

AC_CONFIG_HEADERS([config.h])
AM_INIT_AUTOMAKE(broomie, 0.2.4)


# FCGI option
AC_ARG_ENABLE(fcgi,
    AS_HELP_STRING([--enable-fcgi], [build web interface with fastCGI]),
    enable_fcgi="$enableval",
    enable_fcgi="no"
)
AM_CONDITIONAL(ENABLE_FCGI, test "$enable_fcgi" = "yes")

# oll option
AC_ARG_ENABLE(oll,
    AS_HELP_STRING([--enable-oll], [use oll library]),
    enable_oll="$enableval",
    enable_oll="no"
)
if test "$enable_oll" = "yes"; then
    BRM_USE_OLL="-DUSE_OLL"
    BRM_LIB_OLL="-loll"
else
    BRM_USE_OLL=""
    BRM_LIB_OLL=""
fi
AM_CONDITIONAL(ENABLE_OLL, test "$enable_oll" = "yes")

# tinysvm option
AC_ARG_ENABLE(tinysvm,
    AS_HELP_STRING([--enable-tinysvm], [use tinysvm library]),
    enable_tinysvm="$enableval",
    enable_tinysvm="no"
)
if test "$enable_tinysvm" = "yes"; then
    BRM_USE_TINYSVM="-DUSE_TINYSVM"
    BRM_LIB_TINYSVM="-ltinysvm"
else
    BRM_USE_TINYSVM=""
    BRM_LIB_TINYSVM=""
fi
AM_CONDITIONAL(ENABLE_TINYSVM, test "$enable_tinysvm" = "yes")

# test option
AC_ARG_ENABLE(test,
    AS_HELP_STRING([--enable-test], [build test tools. need gtest.]),
    enable_test="$enableval",
    enable_test="no"
)
AM_CONDITIONAL(ENABLE_TEST, test "$enable_test" = "yes")

# debug option(assert)
AC_ARG_ENABLE(debug,
    AS_HELP_STRING([--enable-debug], [debug with assert]),
    enable_debug="$enableval",
    enable_debug="no"
)
if test "$enable_debug" = "yes"; then
    BRM_DEBUG=""
else
    BRM_DEBUG="-DNDEBUG"
fi
AM_CONDITIONAL(ENABLE_DEBUG, test "$enable_debug" = "yes")


# all option
AC_ARG_ENABLE(all,
    AS_HELP_STRING([--enable-all], [all the options are yes]),
    enable_all="$enableval",
    enable_all="no"
)
if test "$enable_all" = "yes"; then
    BRM_USE_OLL="-DUSE_OLL"
    BRM_LIB_OLL="-loll"
    BRM_USE_TINYSVM="-DUSE_TINYSVM"
    BRM_LIB_TINYSVM="-ltinysvm"
    BRM_DEBUG=""
    AM_CONDITIONAL(ENABLE_FCGI, test "$enable_fcgi" = "no")
    enable_fcgi="yes"
    AM_CONDITIONAL(ENABLE_OLL, test "$enable_oll" = "no")
    enable_oll="yes"
    AM_CONDITIONAL(ENABLE_TINYSVM, test "$enable_tinysvm" = "no")
    enable_tinysvm="yes"
    AM_CONDITIONAL(ENABLE_TEST, test "$enable_test" = "no")
    enable_test="yes"
fi
AM_CONDITIONAL(ENABLE_ALL, test "$enable_all" = "yes")

AC_SUBST(BRM_USE_OLL)
AC_SUBST(BRM_LIB_OLL)
AC_SUBST(BRM_USE_TINYSVM)
AC_SUBST(BRM_LIB_TINYSVM)
AC_SUBST(BRM_DEBUG)

# Checks for programs.
AC_PROG_CXX
AC_PROG_CC
AC_PROG_CPP
AC_LANG(C++)
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET
#AC_PROG_RANLIB

# Checks for libraries.
AC_PROG_LIBTOOL
AC_CHECK_LIB(tokyocabinet, tchdbnew)

# Checks for header files.
AC_CHECK_HEADER(tcutil.h, true, AC_MSG_ERROR([tcutil.h is required]))
AC_CHECK_HEADER(tchdb.h, true, AC_MSG_ERROR([tchdb.h is required]))

if [ test $enable_fcgi = "yes" ]; then
   AC_CHECK_HEADER(fcgi_stdio.h, true, AC_MSG_ERROR([fcgi_stdio.h is required]))
fi

if [ test $enable_test = "yes" ]; then
   AC_CHECK_HEADER(gtest/gtest.h, true, AC_MSG_ERROR([gtest/gtest.h is required]))
fi

if [ test $enable_oll = "yes" ]; then
   AC_CHECK_HEADER(oll/oll.hpp, true, AC_MSG_ERROR([oll/oll.hpp is required]))
fi

if [ test $enable_tinysvm = "yes" ]; then
   AC_CHECK_HEADER(tinysvm.h, true, AC_MSG_ERROR([tinysvm.h is required]))
   AC_CHECK_HEADER(TinySVM/misc.h, true, AC_MSG_ERROR([TinySVM/misc.h is required]))
   AC_CHECK_HEADER(TinySVM/model.h, true, AC_MSG_ERROR([TinySVM/model.h is required]))
   AC_CHECK_HEADER(TinySVM/example.h, true, AC_MSG_ERROR([TinySVM/example.h is required]))
   AC_CHECK_HEADER(TinySVM/base_example.h, true, AC_MSG_ERROR([TinySVM/base_example.h is required]))
   AC_CHECK_HEADER(TinySVM/param.h, true, AC_MSG_ERROR([TinySVM/param.h is required]))
fi


# Checks for typedefs, structures, and compiler characteristics.
AC_HEADER_STDC
AC_HEADER_STDBOOL
AC_TYPE_UINT32_T
AC_TYPE_UINT64_T
AC_C_CONST
AC_C_INLINE
AC_TYPE_SIZE_T
AC_FUNC_CLOSEDIR_VOID
AC_FUNC_STAT
AC_HEADER_DIRENT
AC_PROG_RANLIB
AC_STRUCT_TM


# AC_CONFIG_FILES
AC_OUTPUT([Makefile
                 src/Makefile
                 tests/Makefile
])
